package leetcode.秋招.腾讯;

import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/9/5 21:35
 * @description：
 */
public class Main4 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        if (n < 2) {
            System.out.println(0); return;
        }
        int[] nums = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = in.nextInt();
        }
        int res = 0;
        for (int i = 0; i < nums.length; i++) {
            for (int j = i + 2; j < nums.length; j++) {
                int k = i + 1;
                for (; k < j; k++) {
                    if (nums[k] < nums[i] || nums[k] < nums[j]) {
                        break;
                    }
                }
                if (k == j) {
                    res += 2;
                } else res++;
            }
        }
        System.out.println(res);
    }
}
